<template>
	<view class="container">
		<view class="" style="font-size: 26px;letter-spacing: 1px;m margin: 20px 0;text-align: center;">智慧城市</view>
		<view class="" style="display: flex;align-items: center;margin-top: 20px;">
			<view class="tag">账号：</view>
			<uni-easyinput v-model="user.username" placeholder="请输入账号" />
		</view>
		<view class="" style="display: flex;align-items: center;margin-top: 20px;">
			<view class="tag">密码：</view>
			<uni-easyinput v-model="user.password" type="password" placeholder="请输入密码" />
		</view>
		<view class="" @click="to" style="padding: 15px 0;text-align: center;">没有账号去注册</view>
		<button type="primary" @click="submit" style="margin-top: 0px;">登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					username: "20972",
					password: "123456"
				}
			};
		},
		onLoad(item) {

		},
		onReady() {

		},
		onShow() {

		},
		methods: {
			to() {
				uni.navigateTo({
					url: 'register',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			submit() {
				
				uni.removeStorageSync("token")
				this.post('/prod-api/api/login', this.user).then(res => {
					if (res.code === 200) {
						uni.setStorageSync("token", res.token)
						this.get('/prod-api/api/common/user/getInfo', {

						}, ).then(res => {
							let data = res.user
							uni.setStorageSync("user", data)
							uni.switchTab({
								url: "../home/home"
							})
						})
					}
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});

				})
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: white;
	}
</style>
